package ynu.edu.LoadBalanceConfig;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

public class ThreeTimesLoadBalanceConfig {
    @Bean
    ReactorLoadBalancer<ServiceInstance> RandomLoadBalancer(Environment env, LoadBalancerClientFactory lbf) {
        String name = env.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
        return new ThreeTimesLoadBalancer(lbf.getLazyProvider(name, ServiceInstanceListSupplier.class));
    }
}
